package com.dqhl.community;

import android.app.Application;

import com.arrownock.exception.ArrownockException;
import com.arrownock.im.AnIM;
import com.arrownock.social.AnSocial;
import com.dqhl.community.util.Constant;
import com.dqhl.community.util.Dlog;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import org.xutils.x;

import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.ShareSDK;

/**
 * Created by cheng on 2016/8/29.
 * MyApplication
 */
public class MyApplication extends Application {

    private static MyApplication mInstance = null;
    private AnSocial social;
    private String authentication; //是否认证
    private AnIM anIM;
    private String userId;//用户id
    private String username;
    private String pwd;
    // IWX 是第三方app和微信通信的openapi接口
    private IWXAPI iwxapi;


    public void setUsername(String username) {
        this.username = username;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getPwd() {
        return pwd;
    }

    public String getUsername() {
        return username;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getAuthentication() {
        return authentication;
    }

    public void setAuthentication(String authentication) {
        this.authentication = authentication;
    }

    public MyApplication getInstance() {
        return mInstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        initXUtils();
        ShareSDK.initSDK(this);
        //注册微信第三方
        iwxapi = WXAPIFactory.createWXAPI(this, Constant.WEIXIN_APP_ID, true);
        iwxapi.registerApp(Constant.WEIXIN_APP_ID);
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        Dlog.e("JPush init success");
        initSocial();
        initAnIM();
    }

    public AnSocial getSocial() {
        return social;
    }

    public void setSocial(AnSocial social) {
        this.social = social;
    }

    public AnIM getAnIM() {
        return anIM;
    }

    public void setAnIM(AnIM anIM) {
        this.anIM = anIM;
    }

    /**
     * 初始化 IM++ Social SDK
     */
    private void initSocial() {
        try {
            social = new AnSocial(this, Constant.SOCIAL_KEY);
        } catch (ArrownockException e) {
            e.printStackTrace();
        }
    }

    /**
     * 实例化AnIM
     */
    private void initAnIM(){
        try {
            anIM = new AnIM(getBaseContext(),Constant.SOCIAL_KEY);
        } catch (ArrownockException e) {
            e.printStackTrace();
        }
    }

    /**
     * 初始化 xUtils
     */
    private void initXUtils() {
        x.Ext.init(this);
        x.Ext.setDebug(false); // 是否输出debug日志
    }
}
